using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Text;
using System.Web.UI;
using Medianamik.Core;
using Medianamik.Core.DAL;
using Medianamik.UI.Controls;
using Moq;
using NUnit.Framework;

namespace Medianamik.Tests.Unit.Medianamik.UI
{
    [TestFixture]
    public class BaseMedianamikControlTest
    {
        [Test]
        public void Should_render_label_if_DisplayLabel_is_false()
        {
            var labelValue = "Text that should not be rendered";
            var controlWithoutLabel = new TestControl
                                          {
                                              DisplayLabel = false,
                                              Label = labelValue
                                          };
            controlWithoutLabel.CreateChildControls();
            var htmlOutput = RenderControl(controlWithoutLabel);

            Assert.That(htmlOutput, Is.Not.StringContaining(labelValue));


        }

        [Test]
        public void Should_render_label_if_DisplayLabel_is_true()
        {
            string labelValue = "The quick brown fox jumps over the lazy dog.";
            var controlWithLabel = new TestControl
                                       {
                                           DisplayLabel = true,
                                           Label = labelValue
                                       };
            
            controlWithLabel.CreateChildControls();
            var htmlOutput = RenderControl(controlWithLabel);

            Assert.That(htmlOutput, Is.StringContaining(labelValue));

        }
        

        private string RenderControl(Control control)
        {
            var builder = new StringBuilder();
            var textWriter = new StringWriter(builder);
            var htmlWriter = new HtmlTextWriter(textWriter);
            control.RenderControl(htmlWriter);
            return builder.ToString();
        }

        private class TestControl : BaseMedianamikControl
        {
            public override object GetValue()
            {
                return string.Empty;
            }

            public override Type TypeOfValue
            {
                get { return typeof (string); }
            }

            protected override void CreateControlHierarchy(bool pUseDataSource)
            {
                
            }

            public new void CreateChildControls()
            {
                base.CreateChildControls();
            }
        }
    }
}